package com.game.raceroom.player	
{
	import com.game.main.UserInfoCanvas;
	import com.game.raceroom.loader.ItemLoader;
	import com.game.raceroom.player.item.Car;
	import com.game.raceroom.player.item.Part;
	
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.geom.Rectangle;

	public class CarInfo
	{
		

		//车辆ID
		public var carID:String;
		//玩家定义车辆名称，显示在屏幕上，默认为玩家昵称
		public var carName:String;
		//车辆型号  比如 法拉利KZ200
		public var carType:String;
		public var carIcon:Bitmap;
	    public var carIconData:BitmapData=new BitmapData(1,1);
	    //车辆基准加速度
	    public var baseAccCft:Number=0.2;
		public var accCft:Number=0.00055;
		//车辆基准制动系数
		public var baseBraCft:Number=0.6;
		public var braCft:Number=0.00035;
		//车辆基准最大前进速度
		public var baseMaxUpSpeed:Number=5;
		public var maxUpSpeed:Number=0.6;
		//车辆基准最大倒车速度
		public var baseMaxDownSpeed:Number=3;
		public var maxDownSpeed:Number=0.15;
		//车辆基准环境系数
		public var baseEnvCft:Number=20;
		public var evnCft:Number=20;
		//车辆基准转向系数，数值越低车辆灵敏度越高
		public var baseTurnCft:Number=40;
		public var turnCft:Number=0.25;
		//车辆基准操控系数，固定20,影响车辆失控时间以及位移，同时影响在转向时的侧滑
		public var baseCtlCft:Number=20;
		public var ctlCft:Number=20;
		
		//车辆基准最大耐久
		//车辆基准当前最大耐久
		//当前耐久
		//新车价格
		//配件一览
		//颜色
		//车辆基准冲撞系数
		public var baseConfCft:Number=1.0;
		public var confCft:Number=1.5;
		//车辆基准防御系数
		public var baseDefCft:Number=1.0;
		public var defCft:Number=1.2;
		//车辆基准质量
		public var baseWeight:Number=2000;
		public var weight:Number=1000;
		//车辆基准防侧滑系数
		public var baseSideClipCft:Number=1.0;
		public var sideClipCft:Number=1.0;
		
		public var endure:int=1.0;
		 		
		//碰撞半径
		public var confRadius:Number=40;
        
		//车辆配件信息列表
		public var partList:Array=new Array;
		//碰撞区域
		public var confBox:Rectangle;
		//车辆技能序列，每种车辆最多有8种技能，
		//技能释放效果根据人物等级不同而不同
		
		public var car:Car;
		public var uicanvas:UserInfoCanvas;
 
		public function CarInfo(ui:UserInfoCanvas,car:Car)
		{  
			this.uicanvas=ui;
			this.car=car;
	 
		    
			
		}
			var tendure:Number=0;
			var tmaxUpSpeed:Number=0;
			var taccCft:Number=0;
			var tsideClipCft:Number=0;
			var tturnCft:Number=0;
			var tweight:Number=0;
		public function setCarProp():void{
			this.endure=tendure;
			this.maxUpSpeed=tmaxUpSpeed/1000;
			this.maxDownSpeed=maxUpSpeed*0.6;
			this.accCft=taccCft/100000;
			this.braCft=this.accCft;
			this.sideClipCft=tsideClipCft/100;
			this.turnCft=tturnCft/100;
			this.weight=tweight;
		}
		public function cacuCarProp():void{
			addCarProp(car);
			if(partList){
			for(var i in partList){
				addCarProp((Car)(partList[i]));
			}
			}
			setCarProp();
		}
		public function addCarProp(car:Car):void{
			this.tendure+=car.endure;
			this.tmaxUpSpeed+=car.speed;
			this.taccCft+=car.acccft;
			this.tsideClipCft+=car.sccft;
			this.tturnCft+=car.turncft;
			this.tweight+=car.weight;
			
		}
		public function resetUi( ):void{
           if(uicanvas){
             	uicanvas.setCarInfo(this);
             
           }
		}
		public function setCarInfo(car:Car):void{
			this.car=car;
			this.confRadius=car.confradius;
		}
	 
		public function setPartInfo(car:Car):void{
			//this.partList.clear();
			 tendure=0;
			 tmaxUpSpeed=0;
			 taccCft=0;
			 tsideClipCft=0;
			 tturnCft=0;
			 tweight=0;
			 partList=car.parts;
	        cacuCarProp();
	    	resetUi();
		}
		public function setPartList(list:Array):void{
			 partList=new Array;
			 tendure=0;
			 tmaxUpSpeed=0;
			 taccCft=0;
			 tsideClipCft=0;
			 tturnCft=0;
			 tweight=0;
	    	for(var i in list){
	    		if( list[i]  is Number){
		    		var itm:Part=ItemLoader.getPart(list[i]);
		    		 
		    		 partList.push(itm);	    			
	    		}else if(list[i]  is Object){
		    		var itm:Part=ItemLoader.getPart(list[i].partid);
		    		 
		    		 partList.push(itm);	    			
	    		}

	    		 
	    	}
	        cacuCarProp();
	    	resetUi();
		}
	    //滑动阻力获得
	    var res:Number;
	    var i20000:int=20000;
	    var baseRes:Number=0.9;
	    public function getSlipResistance():Number{
	    	res=(baseRes+weight/i20000)*sideClipCft;
	    	return res;
	    }

	}
}